/**
 * @file norinf_1.h
 * @brief NOR Flash Interface Type 1
 *
 * @author yemt@witsi.cn
 * @date 2012-05-13
 * @version NORINF_1.01
 */
#ifndef NORINF_1_H_
#define NORINF_1_H_

#include "iodef.h"
#include "flash.h"

static inline void flash_unlock1(uint32_t addr)
{
        writew((addr + (0x555 << 1)), AMD_CMD_UNLOCK_START);
}
static inline void flash_unlock2(uint32_t addr)
{
        writew((addr + (0x2AA << 1)), AMD_CMD_UNLOCK_ACK);
}
static inline void flash_unlock_bypass(uint32_t addr)
{
        writew((addr + (0x555 << 1)), AMD_CMD_UNLOCK_BYPASS);
}

static inline void flash_unlock_bypass_reset(uint32_t addr)
{
        writew(addr, AMD_CMD_UNLOCK_BYPASS_RESET1);
        writew(addr, AMD_CMD_UNLOCK_BYPASS_RESET2);
}
static inline void flash_reset(uint32_t addr)
{
        writew(addr, AMD_CMD_RESET);
}

static inline void flash_cfi_query(uint32_t addr)
{
        writew((addr + (0x555 << 1)), FLASH_CMD_CFI);
}

static inline void flash_read_id(uint32_t addr)
{
        writew((addr + (0x555 << 1)), FLASH_CMD_READ_ID);
}
static inline void flash_erase_start(uint32_t addr)
{
        writew((addr + (0x555 << 1)), AMD_CMD_ERASE_START);
}

static inline void flash_erase_block(uint32_t addr)
{
#ifdef CONFIG_NOR_ERASE_SECTOR
        writew(addr, 0x50);
#else
        writew(addr, AMD_CMD_ERASE_BLOCK);
#endif
}

static inline void flash_program_start(uint32_t addr)
{
        writew((addr + (0x555 << 1)), AMD_CMD_WRITE);
}

static inline uint16_t flash_read_device_id(uint32_t addr)
{
        return readw(addr + 0x02);
}


#endif /* NORINF_1_H_ */
